import { defineStore } from 'pinia'
import type { KeepAliveState } from './types'

const name = import.meta.env.VITE_STORE_NAME
export const useKeepAliveStore = defineStore(`${name}-keepAlive`, {
  state: (): KeepAliveState => ({
    keepAliveName: [],
  }),
  actions: {
    // Add KeepAliveName
    async addKeepAliveName(name: string) {
      // eslint-disable-next-line ts/no-unused-expressions
      !this.keepAliveName.includes(name) && this.keepAliveName.push(name)
    },
    // Remove KeepAliveName
    async removeKeepAliveName(name: string) {
      this.keepAliveName = this.keepAliveName.filter(item => item !== name)
    },
    // Set KeepAliveName
    async setKeepAliveName(keepAliveName: string[] = []) {
      this.keepAliveName = keepAliveName
    },
  },
})
